"""
author: liuxu
date: 2025/9/11
description: 测试dtk自带的hipprof工具
"""
import re
import allure
import pytest

from common.logger_ctrl import mylogger
from common.ssh_command import exec_cmd
from base_public.testbase import BasePublic

@pytest.mark.medium
@allure.feature('测试prof相关可执行工具')
class TestProfTool(BasePublic):
    @pytest.mark.performance
    def test_roofline_benchmark(self, test_env):
        """
        测试roofline-benchmark工具
        :return:
        """
        # 执行测试工具命令
        tool_name = 'roofline-benchmark'
        ret, output = exec_cmd(tool_name, cwd=test_env)

        # 检查工具执行结果
        assert ret is True, f"The command '{tool_name}' failed to execute"
        #TODO检查每张卡的性能数据

@pytest.mark.low
@allure.feature('测试运行时可执行工具')
class TestProfTool(BasePublic):
    def test_rocm_agent_enumerator(self, test_env):
        """
        测试rocm_agent_enumerator工具
        :return: gfx000、gfx906、gfx926、gfx928、gfx936
        """
        # 执行测试工具命令
        tool_name = 'rocm_agent_enumerator'
        ret, output = exec_cmd(tool_name, cwd=test_env)

        # 检查工具执行结果
        assert ret is True, f"The command '{tool_name}' failed to execute"
        assert ["gfx000", "gfx906", "gfx926", "gfx928", "gfx936"] == output.strip().split("\n")

    def test_hipconfig(self, test_env):
        """
        测试hipconfig工具
        :return:
        """
        # 执行测试工具命令
        tool_name = 'hipconfig'
        ret, output = exec_cmd(tool_name, cwd=test_env)

        # 检查工具执行结果
        assert ret is True, f"The command '{tool_name}' failed to execute"
        assert "error:" not in output.lower()

    @pytest.mark.skip
    def test_hipInfo(self, test_env):
        """
        测试hipInfo工具
        :return:
        """
        # 执行测试工具命令
        tool_name = 'hipInfo'
        ret, output = exec_cmd(tool_name, cwd=test_env)

        # 检查工具执行结果
        assert ret is True, f"The command '{tool_name}' failed to execute"
        assert "error:" not in output.lower()

    def test_rocm_smi(self, test_env):
        """
        测试rocm-smi工具
        :return:
        """
        # 执行测试工具命令
        tool_name = 'rocm-smi'
        ret, output = exec_cmd(tool_name, cwd=test_env)

        # 检查工具执行结果
        assert ret is True, f"The command '{tool_name}' failed to execute"
        assert "error:" not in output.lower()

